
var timeQcd;
var QSpell = true;

var timeWcd;
var WSpell = true;

var timeEcd;
var efectoE;
var ESpell = true;

function Barra(){ // BARRA QUE MANEJA EL JUGADOR
	this.x = 250;
	this.y = 400;
	this.vx = 0;
	this.w = 64;
	this.h = 16;
	this.m = 0;
	this.started = true;
}


Barra.prototype = {
	move: function() {	
		this.x += this.vx;
	},
	
	estado: function(est){
		switch(est){
			case 0:
				this.w = 64;
				this.h = 16;
			break;
			
			case 1:
				this.w = 96;
			break;
			
			case 2:
				this.w = 64;
			break;
			
			case 3:
				this.w = 32;
			break;
			
		}
	},
	
	barraControles : function(){
		
		if(UP==1){
			for(var i=0; i< bolas.length; i++){
			    bolas[i].start();
				partidaEmpezada = true;
			}
		}
		
		if(R==1){			
			if(this.x + this.w + this.vx <= 500 ){
				this.vx = 8;
				this.m = 1;
			}	
		}else if(R==0 && L== 0){
			this.vx = 0;
			this.m = 0;
		}
		
		if(L==1){
			if(this.x - this.vx >= 0 ){
				this.vx = -8;
				this.m = -1;
			}
		}else if(L==0 && R==0){
			this.vx = 0;
			this.m = 0;
		}
		
		//SPELL Q
		if(Q==1 && partidaEmpezada == true && QSpell == true){
			Q=0;
			QSpell = false;
			timeQcd = setTimeout(function(){trueQcd()},1000);
			disparos.push(new DisparoBasico(this.x + this.w/2,this.y - 10));
		}else{
			Q=0;
		}
		
		//SPELL W
		if(W==1 && partidaEmpezada == true && WSpell == true){
			W=0;
			WSpell = false;
			timeWcd = setTimeout(function(){trueWcd()},10000);
			blocks.push(new Block(this.x + this.w/2,this.y + this.h + 5));
		}else{
			W=0;
		}
		
		//SPELL E
		if(E==1 && partidaEmpezada == true && ESpell == true){
			E=0;
			ESpell = false;
			efecto = 0.5;
			timeEcd = setTimeout(function(){trueEcd()},10000);
			efectoE = setTimeout(function(){finEfectoE()},2000);
		}else{
			E=0;
		}

	},
	
	barraColisiones: function(){
		
		//Colision barra con las paredes
		if(this.m ==  -1){
			if(this.x - this.vx <= 0 ){
				this.vx = 0;
				this.m = 0;
			}
		}else if(this.m == 1){
			if(this.x + this.w + this.vx >= 500 ){
				this.vx = 0;
				this.m = 0;
			}
		}
		
		//COLISIONES CON ITEMS
		for(var x=0; x< items.length;x++){
			if(items[x].y > 500){
				items.splice(x,1);
			}
			if(colisionObjets(this,items[x],3)){
				barra.estado(items[x].type);
				puntuacion = puntuacion + items[x].puntos();
				items.splice(x,1);
			}
		}
		
	},
}

function trueWcd(){
	WSpell = true;
	clearTimeout(timeWcd);
}

function trueQcd(){
	QSpell = true;
	clearTimeout(timeQcd);
}

function trueEcd(){
	ESpell = true;
	clearTimeout(timeEcd);
}

function finEfectoE(){
	efecto = 1;
}

